package com.sky.controller.user;

import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.HistoryOrderService;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "历史订单接口")
public class HistoryOrderControler {

    @Autowired
    private HistoryOrderService historyOrderService;

    @RequestMapping("/historyOrders")
    @ApiOperation("历史订单")
    // 订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消
    public Result<PageResult> page(int page, int pageSize, Integer status) {
        PageResult pageResult = historyOrderService.pageQuery4User(page, pageSize, status);
        return Result.success(pageResult);
    }


    //取消订单
    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancel(@PathVariable("id") Long id) throws Exception {
        historyOrderService.userCancelById(id);
        return Result.success();
    }

    //查询订单详情
    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> details(@PathVariable("id") Long id) {
        OrderVO orderVO = historyOrderService.details(id);
        return Result.success(orderVO);
    }


    //在来一单
    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result repetition(@PathVariable("id") Long id) {
        historyOrderService.repetition(id);
        return Result.success();
    }

    //催单
    @GetMapping("/reminder/{id}")
    @ApiOperation("催单")
    public Result reminder(@PathVariable("id") Long id) {
        historyOrderService.cuidan(id);
        return Result.success();
    }
}
